package com.lancoo.znbkxx.teacher.aibkGenerateTestPaper.aibkPreviewTemplet

import android.text.Html
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.aibkTools.LancooMethod
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.TemplateTypeListInfor
import kotlinx.android.synthetic.main.aibk_adapter_item_questype.view.*

class AibkPreviewTempletAdapter(
        val activity: AppCompatActivity,
        val templateTypeListInfor: TemplateTypeListInfor
) : KBaseRecyclerAdapter(){

    override fun getHolderView(parent: ViewGroup?, position: Int): View? {
        return LayoutInflater.from(activity)
                .inflate(R.layout.aibk_adapter_item_questype, parent, false)
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {
        val typeNo = templateTypeListInfor[holder.layoutPosition].TypeNo
        if(typeNo == "A"){
            holder.convertView.IvQuesTypeIcon.setImageResource(R.mipmap.aibk_icon_tick_green)
        }else if(typeNo == "D"){
            holder.convertView.IvQuesTypeIcon.setImageResource(R.mipmap.aibk_icon_tick_blue)
        }else if(typeNo == "m"||typeNo == "C"){
            holder.convertView.IvQuesTypeIcon.setImageResource(R.mipmap.aibk_icon_tick_orange)
        }else if(typeNo == "X"){
            holder.convertView.IvQuesTypeIcon.setImageResource(R.mipmap.aibk_icon_pen_green)
        }else if(typeNo == "N"){
            holder.convertView.IvQuesTypeIcon.setImageResource(R.mipmap.aibk_icon_pen_blue)
        }else if(typeNo == "Q"||typeNo == "b"||typeNo == "d"||typeNo == "v"||typeNo == "g"||typeNo == "f"){
            holder.convertView.IvQuesTypeIcon.setImageResource(R.mipmap.aibk_icon_pen_orange)
        }else if(typeNo == "E"||typeNo == "F"){
            holder.convertView.IvQuesTypeIcon.setImageResource(R.mipmap.aibk_icon_earphones_green)
        }else if(typeNo == "S"){
            holder.convertView.IvQuesTypeIcon.setImageResource(R.mipmap.aibk_icon_earphones_blue)
        }else if(typeNo == "x"){
            holder.convertView.IvQuesTypeIcon.setImageResource(R.mipmap.aibk_icon_earphones_orange)
        }else{
            holder.convertView.IvQuesTypeIcon.setImageResource(R.mipmap.aibk_icon_synthesis_blue)
        }

        var genreName = templateTypeListInfor[holder.layoutPosition].GenreName
        if(genreName.isEmpty()){
            genreName = templateTypeListInfor[holder.layoutPosition].TypeName
        }
        val quesListSize = templateTypeListInfor[holder.layoutPosition].QuesList.size
        var itemCountAll = 0
        var eachScoreX = ""
        for(i in 0 until quesListSize){
            val itemNum = templateTypeListInfor[holder.layoutPosition].QuesList[i].ItemNum
            val eachScore = templateTypeListInfor[holder.layoutPosition].QuesList[i].ScoreList[0]
            eachScoreX = LancooMethod.killlingDouble(eachScore).toString()
            Log.e("每小题分数", "==========每小题分数X===========$eachScore")
            itemCountAll += itemNum
        }


        holder.convertView.TvQuesTypeName.text = genreName
        holder.convertView.TvQuesTypeInfor.text =
                Html.fromHtml(activity.resources.getString(R.string.aibk_templet_questype_infor, quesListSize, itemCountAll, eachScoreX))
        holder.convertView.IvDelete.visibility = View.GONE//隐藏删除按钮，即屏蔽侧滑事件
    }

    override fun getItemCount(): Int {
        return templateTypeListInfor.size
    }
}